package br.ufrn.engcomp.observer;

/**
 *
 * @author allan
 */
public abstract class Observer {

    private double sinalEscrito;
    private double Ueq;
    private double Yeq;
    private double[] V = new double[2];
    private double[] Erro = new double[2];
    private double[] Xeq = new double[2];
    private double[] deltaX = new double[2];
    private double[] Xck = new double[2];
    private double[] plantaLinear = new double[2];
    private double deltaU;
    private double[][] Ad = {{0.987, 0}, {0.0191, 0.987}};
//    private double[][] Bd = {{0.1425}, {0.0014}};
    private double [][] Bd = {{.4403},{.0043}};

    public Observer() {
//        this.sinalEscrito = .7;
//        this.Ueq = 0.64;
//        this.Yeq = 15;
        this.V[0] = 0;
        this.V[1] = 0;
//        this.Xeq[0] = 0;
//        this.Xeq[0] = 14.77;
//        this.Xeq[1] = 15;
        this.Erro[0] = 0;
        this.Erro[1] = 0;
//        this.Xck[0] = 15;
//        this.Xck[1] = 15;
        this.deltaU = this.sinalEscrito - this.Ueq;
        this.deltaX[0] = this.Xck[0] - this.Xeq[0];
        this.deltaX[1] = this.Xck[1] - this.Xeq[1];

        this.plantaLinear[0] = 0;
        this.plantaLinear[1] = 0;
    }

    public double getXck1() {
        return (Xck[0]);
    }

    public double getXck2() {
        return (Xck[1]);
    }

    public double getErro1() {
        return (Erro[0]);
    }

    public double getErro2() {
        return (Erro[1]);
    }

    public double getUeq() {
        return Ueq;
    }

    public double getYeq() {
        return Yeq;
    }

    public double getDeltaU() {
        return deltaU;
    }

    public double getSinalEscrito() {
        return sinalEscrito;
    }

    public double getXeq1() {
        return Xeq[0];
    }

    public double getXeq2() {
        return Xeq[1];
    }

    public double getDeltaX1() {
        return deltaX[0];
    }

    public double getDeltaX2() {
        return deltaX[1];
    }

    public void setErro(double Erro1, double Erro2) {
        this.Erro[0] = Erro1;
        this.Erro[1] = Erro2;
    }

    public void setXck(double Xck1, double Xck2) {
        this.Xck[0] = Xck1;
        this.Xck[1] = Xck2;
    }

    public void setDeltaU(double deltaU) {
        this.deltaU = deltaU;
    }

    public void setUeq(double Ueq) {
        this.Ueq = Ueq;
    }

    public void setYeq(double Yeq) {
        this.Yeq = Yeq;
    }

    public void setDeltaX(double delta0, double delta1) {
        this.deltaX[0] = delta0;
        this.deltaX[1] = delta1;
    }

    public void setXeq_1(double Xeq) {
        this.Xeq[0] = Xeq;
    }

    public void setSinalEscrito(double sinalEscrito) {
        this.sinalEscrito = sinalEscrito;
    }

    public double getPlantaLinear_1() {
        return plantaLinear[0];
    }

    public double getPlantaLinear_2() {
        return plantaLinear[1];
    }

    public double getV1() {
        return V[0];
    }

    public void setV1(double v1) {
        this.V[0] = v1;
    }

    public double getV2() {
        return V[1];
    }

    public void setV2(double v2) {
        this.V[1] = v2;
    }

    public double[][] getAd() {
        return Ad;
    }

    public double[][] getBd() {
        return Bd;
    }

    //public abstract void calcularObservador(double nivelTanque1, double nivelTanque2);
    public abstract void calcularObservador(double saida);

    public abstract void run(double nivelTanque2);

    public void plantaLinaer(double u) {
//        double atual_1 = plantaLinear[0];
//        double atual_2 = plantaLinear[1];
        plantaLinear[0] = Ad[0][0] * plantaLinear[0] + Bd[0][0] * u;
        plantaLinear[1] = Ad[1][0] * plantaLinear[0] + Ad[1][1] * plantaLinear[1] + Bd[1][0] * u;
    }
}
